var DataTable = Class.create(Enumerable, {
        initialize : function(){                
                this._columns = [];                
                this._rows = [];                
                
        },
        
        /* Iterator for convinience, iterates over all the cells of the table.
        * Returns a triple of the form [row, column, value] */
        _each : function(iterator){
                for(var r=0; r < this._rows.length; r++){
                        for(var c=0; c < this.num_cols(); c++){                                
                                
                                var triple = [r, c, this.get_cell(r, c) ];
                                iterator( triple );
                        }                
                }
        },
        
        get_row :function(index){
                return this._rows[index];
        },
        get_col : function(index){
                return this._cols[index];
        },
        get_cell:function(row_index, col_index){
                return this._rows[row_index][col_index];
        },

        /* Return the max value for a given column */
        get_col_min :function(col_index){
                var curr_min = null;
                for(var r = 0; r < this.num_rows(); r++){
                        var val = this._rows[r][col_index]
                        if(curr_min == null){
                                curr_min = val;
                        }else{
                                if(curr_min > val){ curr_min = val; }
                        }                
                }
                return curr_min;
        },
        get_col_max :function(col_index){
                
                var curr_max = null;
                for(var r = 0; r < this.num_rows(); r++){
                        var val = this._rows[r][col_index]
                        if(curr_max == null){
                                curr_max = val;
                        }else{
                                if(val > curr_max){ curr_max = val; }
                        }                
                }
                return curr_max;
        },
        
        

        get_row_max :function(row_index){
                var curr_max = null;
                for(var c = 0; c < this.num_cols(); c++){
                        var val = this._rows[row_index][c];
                        
                        if(curr_max == null){ curr_max = val; }
                        else{
                                if(val > curr_max){ curr_max = val; }
                        }
                }
                return curr_max;
        },
        
        num_rows : function(){
                return this._rows.length;
        },
        
        num_cols : function(){
                return this._columns.length;
        },
        
        /* Functions that modify the Data Table */
        add_column : function(name){
                this._columns.push(name);
        },
        
        add_rows : function(num_rows){
                for(var i = 0; i < num_rows; i++){
                        var row = new Array(this.num_cols());
                        this._rows.push(row);
                }
        },        
        
        set_value : function(row, col, value){
                this._rows[row][col] = value;                
                
        },
        
        add_row : function(row_array){
                this.add_rows(1);
                var last_index = this.num_rows() - 1;
                
                row_array.each(function(val, col_index){
                        this.set_value(last_index, col_index, val); 
                }, this);
                
        },        
        
        set_row : function(row_index, row_array){
                row_array.each(function(val, col_index){
                        this.set_value(row_index, col_index, val); 
                }, this);
        },
});